<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="saveBtn">save</button>
    <script>
        const saveBtn = document.getElementById('saveBtn');
        // 1. 自定义事件对象 CustomEvent extend Event
        const e1 = new CustomEvent('click', {
            detail: {
                username: 'jack',
                age: 20
            }
        });
        // 2. 绑定事件
        saveBtn.addEventListener('click', (e) => {
            console.log('2', e1.detail);
        });
        // 3. 触发事件
        window.onclick = function () {
            console.log('1');
            saveBtn.dispatchEvent(e1);
            console.log('3');
        }


    </script>

</body>

</html>